Skip to content

Fixed db parameter in data import#17521

Merged
CritasWang merged 4 commits intoapache:masterfrom
LJW21-02:fix/import-data-db-param
Apr 20, 2026
Merged

Fixed db parameter in data import#17521
CritasWang merged 4 commits intoapache:masterfrom
LJW21-02:fix/import-data-db-param

Conversation

@LJW21-02
Copy link
Copy Markdown
Contributor

This pull request makes several changes to improve database option handling and data integrity checks during table import operations in the IoTDB CLI tools. The main updates include refactoring how the database argument is added to import options and enforcing database consistency when importing SQL files.

Improvements to import option handling:

  • Refactored createTableImportCommonOptions() in OptionsUtil.java to no longer add the database option directly; instead, the database option is now explicitly added in each specific import method, allowing for more flexible and accurate configuration.
  • Updated createTableImportCsvOptions() and createTableImportTsFileOptions() to add the database option as a required argument, ensuring the user must specify a target database for these operations. [1] [2]
    image
    image
  • Updated createTableImportSqlOptions() to add the database option (not required), aligning behavior with the expected usage for SQL imports.
    image

Enhancements to data integrity during SQL import:

  • Added a new method extractDbFromSql() in ImportDataTable.java to extract the database name from SQL statements using a regular expression.
  • Modified the SQL import logic to check that the database specified in each SQL statement matches the target database provided by the user; mismatches are reported and the offending statements are skipped.
    image

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves table-model import CLI behavior by refactoring how the --db option is wired into import commands and adding a database-consistency check when importing SQL files.

Changes:

  • Refactors createTableImportCommonOptions() to stop implicitly adding the database option.
  • Makes --db required for table CSV/TSFile imports, and explicitly adds (optional) --db for table SQL imports.
  • Adds SQL parsing logic in ImportDataTable to detect and skip statements whose target database conflicts with the user-provided --db.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java Adds DB extraction from SQL and enforces DB mismatch skipping during SQL import.
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/common/OptionsUtil.java Refactors table import option construction and makes DB required for CSV/TSFile table imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java Outdated
Comment thread iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportDataTable.java Outdated
@CritasWang CritasWang merged commit ce103a3 into apache:master Apr 20, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants